<template>
	<view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+index ">
					<image :src="item.url" mode="aspectFill"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航区域 -->
		<view class="nav-list">
			<view class="nav-item" @click="navItemClick(1)">
				<image src="@/static/nav/shufa.png" class="icon"></image>
				<text>书法</text>
			</view>
			<view class="nav-item" @click="navItemClick(2)">
				<image src="@/static/nav/biancheng.png" class="icon"></image>
				<text>编程</text>
			</view>
			<view class="nav-item" @click="navItemClick(3)">
				<image src="@/static/nav/huahua.png" class="icon"></image>
				<text>画画</text>
			</view>
			<view class="nav-item" @click="navItemClick(4)">
				<image src="@/static/nav/jimu.png" class="icon"></image>
				<text>积木</text>
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<view v-for="(item,index) in floorList" :key="index">
				<my-imageitem :classes="item" @click="imgPreview(item.url)"></my-imageitem>
				
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				swiperList:[],
				navList:[],
				floorList:[]
			};
		},
		onLoad(){
			this.getSwiperList()
			this.getFloorList()
		},
		methods:{
			async getSwiperList(){
				uni.request({
					url:'http://8.134.76.242:8080/yzmimage/home_banner',
					method:'GET',
					data:{},
					dataType:'json',
					sslVerify:true,
					success: (res) => {
						if(res.data.code !==200){
							this.$showMsg()
						}else{
							console.log(res)
							this.$showMsg('请求成功！')
							this.swiperList = res.data.data
						}
						console.log(res)
					}
				})
				 // const res = await uni.$http.get('/yzmimage/home_banner')
				 // console.log(res)
			},
						
			async getFloorList(){
				uni.request({
					url:'http://8.134.76.242:8080/yzmimage/home_floor',
					method:'GET',
					data:{},
					dataType:'json',
					sslVerify:true,
					success: (res) => {
						if(res.data.code !==200){
							this.$showMsg()
						}else{
							console.log(res)
							this.$showMsg('请求成功！')
							this.floorList = res.data.data
						}
						console.log(res)
					}
				})
			},
			
			navItemClick(class_type){
				uni.navigateTo({
					url:'/subpkg/class_list/class_list?class_type='+class_type
				})
			},
			imgPreview(url) {
			            let arr = []
			            this.floorList.forEach((item, index) => {
			                if (item.url) {
			                    arr.push(item.url)
			                }
			            })
			            let index = arr.findIndex(value => value == url)
			            uni.previewImage({
			                current: index,
			                urls: arr,
			            });
			        },
		}
	}
</script>

<style lang="scss">
swiper{
	height: 330rpx;
	.swiper-item,
	image{
		width: 100%;
		height: 100%;
	}
}
.nav-list{
	display: flex;
	justify-content: space-around;
	margin: 16px 0;
	.nav-item{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 10px 0;
		font-size: 13px;
		.icon{
			width: 100%;
			height: 60rpx;
			padding-bottom:5px;
		}
	}
}


.floor-list{
	height: 100%;
	display: flex;
	flex-wrap: wrap;
	margin: 0 10px;
	justify-content: space-between;
	
}

</style>
